[ASAN] tests: Fix leaks
authorColin Walters <walters@verbum.org>
Tue, 29 Nov 2016 03:03:53 +0000 (22:03 -0500)
committerAtomic Bot <atomic-devel@projectatomic.io>
Wed, 30 Nov 2016 18:51:26 +0000 (18:51 +0000)
Just for cleaner sanitizer output.

Closes: #598
Approved by: jlebon

tests/test-basic-c.c
tests/test-keyfile-utils.c
tests/test-libarchive-import.c
tests/test-pull-c.c
tests/test-rollsum.c

index 447c46ea54a18a4f05a950b6e4a1e406f80dd2fd..8e7882b93251db236ae5b0a89459a0da939906f1 100644 (file)
@@ -73,7 +73,6 @@ test_raw_file_to_archive_z2_stream (gconstpointer data)
                            &commit_checksum,
                            &error);
   g_assert_no_error (error);
-  reachable = ostree_repo_traverse_new_reachable ();
   ostree_repo_traverse_commit (repo,
                                commit_checksum,
                                -1,
index 4bf375789d27b53c6fdb451829d623b81e38846b..8fd59163a862882afec21541770bf2bc771a55b0 100644 (file)
@@ -31,7 +31,7 @@ static GKeyFile *g_keyfile;
 static void
 test_get_boolean_with_default (void)
 {
-  GError *error = NULL;
+  g_autoptr(GError) error = NULL;
   gboolean out = FALSE;
 
   GLogLevelFlags always_fatal_mask;
@@ -46,18 +46,21 @@ test_get_boolean_with_default (void)
                                                        FALSE,
                                                        &out,
                                                        &error));
+  g_clear_error (&error);
   g_assert_false (ot_keyfile_get_boolean_with_default (g_keyfile,
                                                        NULL,
                                                        "a_boolean_true",
                                                        FALSE,
                                                        &out,
                                                        &error));
+  g_clear_error (&error);
   g_assert_false (ot_keyfile_get_boolean_with_default (g_keyfile,
                                                        "section",
                                                        NULL,
                                                        FALSE,
                                                        &out,
                                                        &error));
+  g_clear_error (&error);
 
   /* Restore the old mask.  */
   g_log_set_always_fatal (always_fatal_mask);
@@ -86,6 +89,7 @@ test_get_boolean_with_default (void)
                                                  &error));
   g_assert_true (out);
 
+  g_clear_error (&error);
   g_assert_false (ot_keyfile_get_boolean_with_default (g_keyfile,
                                                        "a_fake_section",
                                                        "a_boolean_true",
@@ -97,8 +101,8 @@ test_get_boolean_with_default (void)
 static void
 test_get_value_with_default (void)
 {
-  GError *error = NULL;
-  char *out = NULL;
+  g_autoptr(GError) error = NULL;
+  g_autofree char *out = NULL;
   GLogLevelFlags always_fatal_mask;
   const char *section = "section";
 
@@ -112,18 +116,21 @@ test_get_value_with_default (void)
                                                      "none",
                                                      &out,
                                                      &error));
+  g_clear_pointer (&out, g_free);
   g_assert_false (ot_keyfile_get_value_with_default (g_keyfile,
                                                      section,
                                                      NULL,
                                                      "none",
                                                      &out,
                                                      &error));
+  g_clear_pointer (&out, g_free);
   g_assert_false (ot_keyfile_get_value_with_default (g_keyfile,
                                                      section,
                                                      NULL,
                                                      "something",
                                                      &out,
                                                      &error));
+  g_clear_pointer (&out, g_free);
 
   /* Restore the old mask.  */
   g_log_set_always_fatal (always_fatal_mask);
@@ -135,6 +142,7 @@ test_get_value_with_default (void)
                                                &out,
                                                &error));
   g_assert_cmpstr (out, ==, "foo");
+  g_clear_pointer (&out, g_free);
 
   g_assert (ot_keyfile_get_value_with_default (g_keyfile,
                                                section,
@@ -143,6 +151,7 @@ test_get_value_with_default (void)
                                                &out,
                                                &error));
   g_assert_cmpstr (out, ==, "correct");
+  g_clear_pointer (&out, g_free);
 
   g_assert_false (ot_keyfile_get_value_with_default (g_keyfile,
                                                        "a_fake_section",
@@ -150,6 +159,8 @@ test_get_value_with_default (void)
                                                        "no value",
                                                        &out,
                                                        &error));
+  g_clear_error (&error);
+  g_clear_pointer (&out, g_free);
 }
 
 static void
index 05c5568d34f4b5a65c00cdbb0ac6fdbab15933b0..254d4143196c081b3ebe30bf34043dc9edd637f2 100644 (file)
@@ -180,7 +180,7 @@ static void
 test_libarchive_autocreate_empty (gconstpointer data)
 {
   TestData *td = (void*)data;
-  GError *error = NULL;
+  g_autoptr(GError) error = NULL;
   struct archive *a = archive_read_new ();
   OstreeRepoImportArchiveOptions opts = { 0, };
   glnx_unref_object OstreeMutableTree *mtree = ostree_mutable_tree_new ();
@@ -198,7 +198,7 @@ static void
 test_libarchive_error_device_file (gconstpointer data)
 {
   TestData *td = (void*)data;
-  GError *error = NULL;
+  g_autoptr(GError) error = NULL;
   struct archive *a = archive_read_new ();
   OstreeRepoImportArchiveOptions opts = { 0, };
   glnx_unref_object OstreeMutableTree *mtree = ostree_mutable_tree_new ();
@@ -563,6 +563,7 @@ int main (int argc, char **argv)
 
   r = g_test_run();
 
+  g_clear_object (&td.repo);
   if (td.tmpd && g_getenv ("TEST_SKIP_CLEANUP") == NULL)
     (void) glnx_shutil_rm_rf_at (AT_FDCWD, td.tmpd, NULL, NULL);
   g_free (td.tmpd);
index d784312fb7b0cf70dc99fc29a96b1d80ae1e0071..43d5d61d480213666f59b727582e0b2358297381 100644 (file)
@@ -127,6 +127,7 @@ int main (int argc, char **argv)
   g_test_add_data_func ("/test-pull-c/multi-ok-error-repeat", &td, test_pull_multi_error_then_ok);
 
   r = g_test_run();
+  g_clear_object (&td.repo);
 
   return r;
 }
index 97aeb0ae201a3150540000f7f0b56e718797f265..1ed99645450f097154402f8c07db9d1e7c469c00 100644 (file)
@@ -74,8 +74,8 @@ test_rollsum (void)
 #define MAX_BUFFER_SIZE 1000000
   gsize i;
   int len;
-  unsigned char *a = malloc (MAX_BUFFER_SIZE);
-  unsigned char *b = malloc (MAX_BUFFER_SIZE);
+  g_autofree unsigned char *a = malloc (MAX_BUFFER_SIZE);
+  g_autofree unsigned char *b = malloc (MAX_BUFFER_SIZE);
   g_autoptr(GRand) rand = g_rand_new ();
 
   /* These two buffers produce the same crc32.  */